var express = require('express');
var router = express.Router();
// var data=require('../data/index.js')
var Coe=require('../data/home/coe.js')
var Order=require('../data/home/order.js')
// 登录接口
let userList = [
    { username: 'admin1', password: '111',},
    { username: 'admin2', password: '222' },
    { username: 'admin3', password: '333' },
    { username: 'admin4', password: '444' },
];
router.post('/login', function (req, res, next) {
    console.log(req);
    console.log(userList) ;

    let info = userList.findIndex(item => {
        return req.body.username === item.username && req.body.password === item.password

    })

    if (info >= 0) {
        res.send({
            msg: "登录成功",
            code: '200'
        })
    }
    if (req.body.username !== userList.username) {
        res.send({
            msg: "账号不正确，请重新输入",
            code: "100"
        })

    }

    if (req.body.password !== userList.password) {
        res.send({
            msg: "密码不正确，请重新输入",
            code: "200"
        })
    }
    console.log(info);
})

//注册接口
router.post('/register', function (req, res, next) {

    if (userList.length + 1 === userList.push(req.body)) {
        console.log(userList);
        res.send({
            msg: "注册成功",
            code: '200'
        })
    } else {
        res.send({
            msg: "注册失败",
            code: '500'
        })
    }
})

// 修改个人信息
let editText=[
    { name: "admin1", pic:'http://127.0.0.1:3000/static/images/111.jpg'
  
 }
]
router.post('/edit', function (req, res, next) {
    if (editText.length + 1 === editText.push(req.body)) {
        res.send({
            msg: "修改成功",
            code: '200'
        })
    } else {
        res.send({
            msg: "修改失败",
            code: '500'
        })
    }

})

// 显示个人信息
router.get('/info', function (req, res, next) {
    res.send(editText)
})
//显示收藏信息列表
router.get('/list',function(req,res,next){
    res.send(Coe)
})
//订单列表
router.get('/order/list',function(req,res,next){
    console.log("Order",Order)
    res.send(Order)
})

module.exports = router;